package com.hong.servicehosp.controller;

import com.hong.commonutil.result.Result;
import com.hong.model.model.hosp.Hospital;
import com.hong.model.vo.hosp.DepartmentVo;
import com.hong.model.vo.hosp.HospitalQueryVo;
import com.hong.model.vo.hosp.HospitalSetQueryVo;
import com.hong.servicehosp.mapper.HospitalSetMapper;
import com.hong.servicehosp.service.DepartmentService;
import com.hong.servicehosp.service.HospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

//@CrossOrigin
@RequestMapping("/admin/hosp/hospital/")
@RestController
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;

    @ApiOperation("获取医院列表")
    @GetMapping("list/{page}/{limit}")
    public Result listHospital(@PathVariable Integer page, @PathVariable Integer limit, HospitalQueryVo hospitalQueryVo) throws ExecutionException, InterruptedException {
        Page<Hospital> pageModel = hospitalService.selectHospitalByPage(page, limit, hospitalQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation("更新医院的上线状态")
    @GetMapping("updateHospStatus/{id}/{status}")
    public Result updateHospitalStatus(@PathVariable String id, @PathVariable Integer status) {
        hospitalService.updateStatus(id, status);
        return Result.ok();
    }

    @ApiOperation("获取医院详情")
    @GetMapping("showHospDetail/{id}")
    public Result showHospDetail(@PathVariable String id) throws ExecutionException, InterruptedException {
        Map<String, Object> hospital = hospitalService.getHospById(id);
        return Result.ok(hospital);
    }
}
